<template>
    <div class="apppadding bgfff">
        <bDetail :instance="pForm" class="form" title="预约人信息" cover="80%"></bDetail>
    </div>
    <div class="apppadding bgfff">
        <bDetail :instance="pForm" label_prop="labels_info" class="form" title="订单信息" cover="80%"></bDetail>
    </div>
    <div class="blank"></div>
    <div v-if="pForm.data.status === NURSING_APPOINTMENT_STATUS.未支付">
        <Button type="primary" :plain="true" v-if="but.has('nursing_appointment:pay')" @click="() => pForm.pay()">
            {{ but.get('nursing_appointment:pay') }}
        </Button>
    </div>
    <div v-else-if="pForm.data.status === NURSING_APPOINTMENT_STATUS.已支付">
        <Button type="primary" :plain="true" v-if="but.has('nursing_appointment:audit:no')" @click="auditNo">
            {{ but.get('nursing_appointment:audit:no') || '退回' }}</Button>
        <Button type="primary" v-if="but.has('nursing_appointment:audit')" @click="show = true">
            {{ but.get('nursing_appointment:audit') || '审核' }}</Button>
    </div>
    <Popup v-model:show="show" position="bottom" title="选择科室" @open="() => pForm.getDepartmentTree()">
        <Picker :columns="pForm.departmentTree" :columns-field-names="defaultProps"
            @confirm="(node) => { pForm.handleDepartmentClick(node.selectedValues.pop()); show = false; pForm.show = true }">
        </Picker>
    </Popup>
    <Popup v-model:show="pForm.show" position="bottom" title="审核">
        <div v-if="pForm.nurseLeader.length === 0">
            未选择科室或科室内暂无护士
        </div>
        <Picker v-else :columns="pForm.nurseLeader" :columns-field-names="defaultProps"
            @confirm="(node) => { pForm.nurseLeaderId = node.selectedValues.pop(); pForm.audit() }">
        </Picker>
    </Popup>
</template>

<script lang="ts" setup>
import bDetail from "@/components/public/b_detail.vue";
import { IForm } from "@b/index/nursing_appointment";
import { useRoute } from "vue-router";
import { pagebuttonStore } from "@b/store";
import { Button, Popup, Picker, Radio, RadioGroup } from "vant";
import bMessageBox from "@m/components/widget/b_message_box";
import { NURSING_APPOINTMENT_STATUS } from "@b/model/enum";
import { ref } from "vue";

const pForm = new IForm();
const id = useRoute().query.id;
pForm.id = Number(id);
const but = pagebuttonStore().button;
pForm.setData();
pForm.init();
const show = ref(false);
const defaultProps = {
    children: 'departments',
    text: 'name',
    value: 'id'
}

const auditNo = () => {
    bMessageBox('未通过原因', {
        title: '退回',
        placeholder: '请输入退回原因',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
    }).then((message) => {
        pForm.auditNo(message)
    })
}
</script>
